﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;



namespace engine
{

    static class Text2D
    {
        
        private static SpriteBatch spriteBatch;
        public static SpriteFont spriteFont;

        public static void Initialize(SpriteBatch spritebatch)
        {
            spriteBatch = spritebatch;
        }

        public static void LoadContent()
        {
            spriteFont = Engine.Instance.Content.Load<SpriteFont>("Fonts\\Arial");
        }

        public static void Draw(string text)                         // Basic DrawText function taking a string as argument
        {
            StringBuilder buffer = new StringBuilder();
            buffer.AppendFormat(text);
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
            spriteBatch.DrawString(spriteFont, buffer.ToString(), new Vector2(0.0f, 0.0f), Color.DarkBlue);
            spriteBatch.End();
        }

        public static void Draw(string text, Vector2 fontPos)       // Overloaded DrawText function taking a string and position coordinates as a Vector2 variable
        {
            StringBuilder buffer = new StringBuilder();
            buffer.AppendFormat(text);
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
            spriteBatch.DrawString(spriteFont, buffer.ToString(), fontPos, Color.DarkBlue);
            spriteBatch.End();
        }

        public static void Draw(string text, Vector2 fontPos, Color color)       // Overloaded DrawText function taking a string and position coordinates as a Vector2 variable and font color
        {
            StringBuilder buffer = new StringBuilder();
            buffer.AppendFormat(text);
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
            spriteBatch.DrawString(spriteFont, buffer.ToString(), fontPos, color);
            spriteBatch.End();
        }

        public static void Draw(string text, Vector2 fontPos, Color color, Vector2 scale)       // Overloaded DrawText function taking a string and position coordinates as a Vector2 variable, font color and font scale.
        {
            StringBuilder buffer = new StringBuilder();
            buffer.AppendFormat(text);
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
            spriteBatch.DrawString(spriteFont, buffer.ToString(), fontPos, color, 0, new Vector2(0.0f, 0.0f), scale, SpriteEffects.None, 0);
            spriteBatch.End();
        }
        
        // More fancy overloads comming soon :)
    }
}
